import Taro from "@tarojs/taro";
import { Component, useState } from "react";
import { Cell, Button, SafeArea } from '@nutui/nutui-react-taro'
import styles from "./index.scss";
import Seconddep from "./seconddep";
import { queryScheduleDepts } from "@/services/register";
import { formatDate, calculateTime } from "@/utils/repeated";
import { useEffect } from "react";
import Layout from "@/components/Layout";

export default () => {

  const [list, setList] = useState([]);

  const goTo = (item) => {
    Taro.navigateTo({
      url: `/pages/register/selectschedule/index?deptCode=${item?.deptCode}&deptName=${item?.deptName}`,
    });
  }

  useEffect(() => {
    queryScheduleDepts({
      startDate: formatDate(new Date(), "yyyy-MM-dd"),
      endDate: calculateTime(7),
    }).then((res) => {
      setList(res);
    });
  }, []);

  return (
    <Layout title="选择科室">
    <view className={styles.selectdepWarp}>
      <Cell.Group>
      {list.map((item) => {
        return (
          <Cell
            className="nutui-cell-clickable"
            title={item.deptName}
            align="center"
            extra={<i role="img" class="weui-icon-arrow-bold"></i>}
            onClick={() => goTo(item)}
          />
        );
      })}
      </Cell.Group>
      {/* {list.map((item) => {
        return <Seconddep item={item}></Seconddep>;
      })} */}
      <SafeArea position="bottom" />
    </view>
    </Layout>
  );
};
